package models;

import play.*;
import play.db.jpa.*;

import javax.persistence.*;

import java.util.*;

import models.RegisteredUser;
import models.Tutorial;

/**
 * This is the EditRequest class which has the attributes edit, tutorialId,
 * requesterId, repliedId, isApproved, isChecked. There's a list of requesters
 * which is related to the registered users. There's a toString method that i
 * use it further on in displaying the requests.
 * 
 * 
 * @author Rana A. Zakaria
 */

@Entity
public class EditRequest extends Model {

	public String edit;
	public long tutorialId;
	public long requesterId;
	public long replierId;
	public boolean isApproved;
	public boolean isChecked;

	@ManyToMany(mappedBy = "editRequest", cascade = CascadeType.ALL)
	public List<RegisteredUser> requestersList;

	/**
	 * This method returns a string of user name and which tutorial does he wish
	 * to edit
	 * 
	 * 
	 * @author Rana A. Zakaria
	 */
	public String toString() {
		RegisteredUser user = RegisteredUser.findById(this.requesterId);
		Tutorial t = Tutorial.findById(this.tutorialId);
		String s = user.name + " wishes to edit the" + t.Title + "tutorial.";
		return s;

	}

	/**
	 * This method returns the value of the varible isApproved
	 * 
	 * @return boolean true or false
	 * 
	 * @author Marwa
	 */
	public boolean isApproved() {
		return isApproved;
	}

	/**
	 * This method sets the value of the variable isApproved
	 * 
	 * @param isApproved
	 *            which is whether the editRequest is approved or not.
	 * @author Marwa
	 */
	public void setApproved(boolean isApproved) {
		this.isApproved = isApproved;
	}

	public EditRequest(String edited, long tutId, long requesterId,
			long replierId, boolean isApproved, boolean isChecked) {
		this.edit = edited;
		this.tutorialId = tutId;
		this.requesterId = requesterId;
		this.replierId = replierId;
		this.isApproved = isApproved;
		this.isChecked = isChecked;
		requestersList = new ArrayList<RegisteredUser>();
	}
}
